﻿// 
// Created By: Xiaofeng.Gu 2021/03/18
//  

#include "CybertronTaskRunnerPoolServer.hpp"
#include"TaskRunnerPoolRestSrv.hpp"
#include <thread>
#pragma warning(disable:4819)
using namespace cybertron;

int main(int argc, char* argv[])
{
	int CoreServerPort = 23790;
	int HttpServerPort = 15000;
	for (int i = 1; i < argc; ++i)
	{
		std::string arg = argv[i];
		if (arg == "--core")
		{
			++i;
			if (i < argc)
			{
				CoreServerPort = atoi(argv[i]);
			}
		}
		else if (arg == "--http")
		{
			++i;
			if (i < argc)
			{
				HttpServerPort = atoi(argv[i]);
			}
		}
	}

	cybertron::setupLogFile("CybertronTaskRunnerPool");
	std::shared_ptr<CybertronTaskRunnerPoolServer> pServer;
	pServer = std::make_shared<CybertronTaskRunnerPoolServer>();

	CTaskRunnerPoolRestSrv::GetInstance()->init(HttpServerPort, pServer);
	if (!pServer->initialize())
	{
		logError("Failed to initialize server!");
		return 0;
	}
	pServer->listen(CoreServerPort);
	pServer->run();
	pServer->close();
	pServer = nullptr;

	return 0;
}
